#!/bin/bash
# This script generates a XML Scene file for the Oxsipgen
# It's interesting to use this script to generate quite long scene
# files with similar sub-scene file
# LICENSE: GPL v2
# copyleft Christophe Vandeplas 
#      christophe@vandeplas.com


START_NUMBER="6000" 
END_NUMBER="6024"  
# end number cannot be higher than 6165, 
# otherwise libs are acting weird
#END_NUMBER="6499"   
SLEEP=1;

GLOBAL_USER="101"
GLOBAL_PASS="101"
GLOBAL_DEST="105"
GLOBAL_SERVER="192.168.1.23"
GLOBAL_SCENEFILE="xpressionPhoneMail/scen8.scen"
GLOBAL_REPEATS="5"

FILENAME="main0.xml"

CONTENT="";

saveToFile()
{
  echo -e ${CONTENT} > ${FILENAME}
}
writeBeginEnd() 
{
  CONTENT=\
"<oxsipgen> \n
${CONTENT} \n
</oxsipgen>";
}

writeGlobal() 
{
  CONTENT=\
"${CONTENT} \n
 <global>\n
  <user>${GLOBAL_USER}</user>\n
  <pass>${GLOBAL_PASS}</pass>\n
  <dest>${GLOBAL_DEST}</dest>\n
  <server>${GLOBAL_SERVER}</server>\n
  <scene>${GLOBAL_SCENEFILE}</scene>\n
  <repeats>${GLOBAL_REPEATS}</repeats>\n
 </global>\n
"
  
}

writeThreads()
{
  for (( i = ${START_NUMBER}; i <= ${END_NUMBER}; i++  )); do
  declare -i i1;
  i1=$i;
  i1=${i1}+1
  declare -i j1;
  j1=${j1}+1;
  CONTENT=\
"${CONTENT}\n
 <thread>\n
  <user>${i}</user>\n
  <pass>${i}</pass>\n
  <dest>${i1}</dest>\n
  <sleep>${j1}000</sleep>\n
 </thread>\n
"  
  done
}

j1=1
writeGlobal;
writeThreads
writeBeginEnd;
saveToFile;
